<template>
    <view class="content">
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="txt">{{item.name}} <span>{{item.tel}}</span><span>{{item.sex}}</span></view>
			<view class="txt1"><span v-if="item.is_type==1">默认</span>{{item.city}} {{item.address}}</view>
			<view class="txt2">
				<view><image @tap="acquiesce(index)" v-if="type==1" :src="item.checks==true?'/static/wxicon2.png':'/static/wxicon1.png'" mode="aspectFill"></image></view>
				<view @tap="remove(index)">删除</view>
				<!-- <view @tap="jump(item)">编辑</view> -->
			</view>
			<view class="xgicon" @tap="jumps(item)"><image src="/static/edicon.png" mode="widthFix"></image></view>
		</view>
       <view class="mraddr" v-if="list.length==0">
		   <image src="/static/mraddr.png" mode="widthFix"></image>
		   <view>暂无地址~</view>
	   </view>
	   <view class="morder" v-if="more==1&&list.length>0">没有更多数据</view>
	   <view class="xzbtn" @tap="jump('./Addaddress?id=0')">新增地址</view>
    </view>
</template>

<script>
const app = getApp();
export default {
    data() {
        return {
			type:0,
			page:0,
			list:[],
			more:0,
			type:0
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        var that = this;
		this.type = options.type?options.type:0
		this.page=0;
	},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
		this.getList();
	},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
    	this.page = 0;
    	uni.hideNavigationBarLoading();
    	uni.stopPullDownRefresh();
    	this.getList();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
    	this.page++;
    	this.getList();
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
		jumps(item){
			uni.setStorageSync('addrcon', item)
			uni.navigateTo({
				url:'./Addaddress'
			})
		},
		getList(){
			app.globalData.api.request('Address/addressList', {
				page:this.page
			}, 'POST', 'form').then((res) => {
				if (res.code == 0) {
					this.list=this.page>0?this.list.concat(res.data):res.data;
					this.more = res.data.length==0?1:0
				}else{
					app.globalData.show(res.msg)
				}
			});
		},
		jump(url){
			uni.setStorageSync('addrcon', '')
			uni.navigateTo({
				url:url
			})
		},
		remove(idx){
			var that = this;
			var id=that.list[idx].id;
			uni.showModal({
		        title: '温馨提示',
		        content: '确定删除？',
		        cancelColor: "#c23038",
		        success(res) {
		            if (res.confirm) {
		               app.globalData.api.request('Address/addressDel', {
		               	id:id,
		               }, 'POST', 'form').then((res) => {
		               	if (res.code == 0) {
							that.list.splice(idx,1)
		               		app.globalData.show(res.msg)
		               	}else{
		               		app.globalData.show(res.msg)
		               	}
		               });
		            } else if (res.cancel) {
		                ////console.log('用户点击取消')
		            }
		        }
		    })
		},
		acquiesce(idx){
			var that = this;
			this.list[idx].checks = true
			var pages = getCurrentPages();
			var prev = pages[pages.length - 2];
			prev.$vm.address = this.list[idx];
			prev.$vm.addrtype = 1;
			uni.navigateBack()
		}
	}
};
</script>
<style>
	.xgicon{
		width: 30px;
		height: 30px;
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		top: 15rpx;
		right: 20rpx;
	}
	.xgicon>image{
		width: 16px;
		height: auto;
	}
	.txt2>view:nth-child(2),.txt2>view:nth-child(3){
		float: right;
		width: auto;
		height: 30px;
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		color: #666666;
		line-height: 30px;
	}
	.txt2>view:nth-child(3){
		margin-right:10px;
	}
	.txt2>view:nth-child(1)>image{
		width: 22px;
		height: 22px;
		border-radius: 22px;
	}
	.txt2>view:nth-child(1){
		width: auto;
		height: 30px;
		display: inline-flex;
		justify-content: center;
		align-items: center;
	}
	.txt2{
		width: 100%;
		height: 30px;
		display: table;
		margin-top: 10px;
	}
	.txt1>span{
		background: #FADD43;
		border-radius: 4rpx;
		width: auto;
		height: auto;
		display: inline-block;
		margin-right: 10px;
		color: #FFFFFF !important;
		padding: 0px 10px;
	}
	.txt1{
		width: 100%;
		height: auto;
		display: table;
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		color: #333333;
		line-height: 42rpx;
		margin-top: 7px;
		padding-bottom: 7px;
		border-bottom: 1px solid #EEEEEE;
	}
	.txt>span{
		font-family: PingFang SC;
		font-weight: 400 !important;
		font-size: 26rpx !important;
		color: #666666 !important;
		margin-left: 10px;
	}
	.txt{
		width: 100%;
		height: auto;
		display: table;
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 32rpx;
		color: #333333;
	}
	.list{
		width: 702rpx;
		height: auto;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 30rpx 0rpx rgba(197,197,197,0.3);
		border-radius: 10rpx;
		margin-top: 30rpx;
		margin-left: 24rpx;
		box-sizing: border-box;
		padding: 20rpx;
		position: relative;
	}
	.content{
		padding-bottom: 100px;
	}
	.xzbtn{
		width: 660rpx;
		height: 90rpx;
		background: #FADD43;
		border-radius: 50px;
		text-align: center;
		line-height: 90rpx;
		position: fixed;
		left: 45rpx;
		bottom: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 36rpx;
		color: #FFFFFF;
	}
	page{
		background-color: #f6f6f6;
	}
	.mraddr{
		width: 100%;
		height:calc(100vh - 200px);
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}
	.mraddr>image{
		width: 250rpx;
		height: auto;
		display: table;
	}
	.mraddr>view{
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 26rpx;
		color: #333333;
		margin-top: 30px;
	}
</style>
